home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / LITTLE / BMSRC.ZIP / LEVELMAP.S < prev    next >
Encoding:
Text File  |  1996-03-25  |  10.5 KB  |  452 lines

  1. *=======================================================*
  2. *    LevelMap: latest update 25/03/96        *
  3. *=======================================================*
  4. *    Display the 2D map.                *
  5. *=======================================================*
  6.  
  7. *-------------------------------------------------------*
  8. *    Find map x,y bounds for scaling            *
  9. *-------------------------------------------------------*
  10.     txtlong
  11. *-------------------------------------------------------*
  12. adjust_map:
  13. *-------------------------------------------------------*
  14.     move.l    Line_Array,a0
  15.     move.l    Vertex_Array,a1
  16.     move.l    #32760,d4            ; x map min
  17.     move.l    #-32760,d5            ; x map max
  18.     move.l    #32760,d6            ; y map min
  19.     move.l    #-32760,d7            ; y map max
  20.     move.w    NumLines,d0    
  21.     subq.w    #1,d0
  22. *-------------------------------------------------------*
  23. *    Search Xmap min, Xmap max, Ymap min & Ymap max    *
  24. *-------------------------------------------------------*
  25. .for_lines:
  26.     moveq    #0,d1
  27.     moveq    #0,d2
  28.     movem.w    (a0),d1-d2            ; linedef from d1 to d2
  29.     move.w    Vertex_y(a1,d2.l*4),d3        ; y2
  30.     ext.l    d3
  31.     cmp.l    d3,d6
  32.     ble.s    .test2
  33.     move.l    d3,d6
  34.     bra.s    .test3
  35. .test2:    cmp.l    d3,d7
  36.     bge.s    .test3
  37.     move.l    d3,d7
  38. .test3:    move.w    Vertex_x(a1,d2.l*4),d3        ; x2
  39.     ext.l    d3
  40.     cmp.l    d3,d4
  41.     ble.s    .test4
  42.     move.l    d3,d4
  43.     bra.s    .test5
  44. .test4:    cmp.l    d3,d5
  45.     bge.s    .test5
  46.     move.l    d3,d5
  47. .test5:    move.w    Vertex_y(a1,d1.l*4),d3        ; y1
  48.     ext.l    d3
  49.     cmp.l    d3,d6
  50.     ble.s    .test6
  51.     move.l    d3,d6
  52.     bra.s    .test7
  53. .test6:    cmp.l    d3,d7
  54.     bge.s    .test7
  55.     move.l    d3,d7
  56. .test7:    move.w    Vertex_x(a1,d1.l*4),d3        ; x1
  57.     ext.l    d3
  58.     cmp.l    d3,d4
  59.     ble.s    .test8
  60.     move.l    d3,d4
  61.     bra.s    .next
  62. .test8:    cmp.l    d3,d5
  63.     bge.s    .next
  64.     move.l    d3,d5
  65. .next:    lea    Line_len(a0),a0            ; Next line
  66.     dbf    d0,.for_lines
  67.  
  68. *-------------------------------------------------------*
  69. *    Calculate Dx = Xmap max - Xmap min        *
  70. *              Dy = Ymap max - Ymap min        *
  71. *-------------------------------------------------------*
  72.     sub.l    d4,d5
  73.     sub.l    d6,d7
  74. *-------------------------------------------------------*
  75. *    Calculate Min( width / Dx ; height / Dy )    *
  76. *-------------------------------------------------------*
  77.     move.w    width,d0
  78.     swap    d0
  79.     clr.w    d0
  80.     divu.l    d5,d0
  81.     move.w    height,d1
  82.     swap    d1
  83.     clr.w    d1
  84.     divu.l    d7,d1
  85.     cmp.l    d1,d0
  86.     ble.s    .small
  87.     move.l    d1,d0
  88. .small:    move.l    d4,xmapmin            ; save xmap min
  89.     move.l    d6,ymapmin            ; save ymap min
  90.     move.l    d0,X_Y_map_Corr            ; save smaller_one
  91.     rts
  92.     
  93. *-------------------------------------------------------*
  94. *    This function displays the level's map when    *
  95. *    the player press the TAB key.            *
  96. *-------------------------------------------------------*
  97.     txtlong
  98. *-------------------------------------------------------*
  99. display_map:
  100. *-------------------------------------------------------*
  101.     tst.b    map_enabled
  102.     bne.s    .go
  103.     rts
  104. *-------------------------------------------------------*
  105. *    Main map display routine            *
  106. *-------------------------------------------------------*
  107. .go:    move.l    xmapmin,a2
  108.     move.l    ymapmin,a3
  109.     move.l    Vertex_Array,a1
  110.     move.w    NumLines,d0    
  111.     subq.w    #1,d0
  112.     move.l    Line_Array,a0
  113. .for_lines2:
  114.     movem.w    (a0),d1-d3            ; from, to, attributes                
  115.     move.w    #$ffe0,d5            ; wall color is yellow
  116.  
  117.     btst    #7,d3                ; test is wall mustn't be
  118.     bne.s    .next_line            ;   on map
  119.  
  120.     move.w    d3,d4                ; test if wall is already
  121.     and.w    #$100,d4            ;   on map, also if never
  122.     beq.s    .next_line            ;   seen before
  123.  
  124. .show_wall:
  125.     btst    #0,d3
  126.     beq.s    .not_external_wall
  127.     move.w    #$f800,d5            ; wall color is red            
  128. .not_external_wall:
  129. .display_level:
  130.     move.w    Vertex_y(a1,d2.w*4),d6        ; y2
  131.     ext.l    d6
  132.     sub.l    a3,d6
  133.     mulu.l    X_Y_map_Corr,d6
  134.     swap    d6
  135.     move.w    height,d4
  136.     subq.w    #1,d4
  137.     sub.w    d6,d4
  138.  
  139.     move.w    Vertex_x(a1,d2.w*4),d3        ; x2
  140.     ext.l    d3
  141.     sub.l    a2,d3
  142.     mulu.l    X_Y_map_Corr,d3
  143.     swap    d3
  144.  
  145.     move.w    Vertex_y(a1,d1.w*4),d6        ; y1
  146.     ext.l    d6
  147.     sub.l    a3,d6
  148.     mulu.l    X_Y_map_Corr,d6
  149.     swap    d6
  150.     move.w    height,d2
  151.     subq.w    #1,d2
  152.     sub.w    d6,d2
  153.  
  154.     move.w    Vertex_x(a1,d1.w*4),d1        ; x1
  155.     ext.l    d1
  156.     sub.l    a2,d1
  157.     mulu.l    X_Y_map_Corr,d1
  158.     swap    d1
  159.     bsr    display_line
  160. .next_line:
  161.     lea    14(a0),a0            ; next line
  162.     dbf    d0,.for_lines2
  163.  
  164.     bsr    Display_Player_Position
  165.     rts
  166.  
  167.  
  168. *-------------------------------------------------------*
  169. *    Draw a colored line between 2 points        *
  170. *-------------------------------------------------------*
  171. *        d1 : X1        d2 : Y1            *
  172. *        d3 : X2        d4 : Y2            *
  173. *        d5 : color of the line            *
  174. *-------------------------------------------------------*
  175.     txtlong
  176. *-------------------------------------------------------*
  177. display_line:
  178. *-------------------------------------------------------*
  179.     movem.l        d0-d7/a0-a2,-(sp)
  180. *-------------------------------------------------------*
  181.     move.w        d5,a2
  182.  
  183.     rept        0
  184.     
  185. *-------------------------------------------------------*
  186. *    Clip line [d1.w,d2.w -> d3.w,d4.w]        *
  187. *-------------------------------------------------------*
  188. .clip_line:
  189. *-------------------------------------------------------*
  190.     move.w        height,d7
  191.     cmp.w        d2,d4
  192.     bpl.s        .sort_y1y2
  193.     exg        d1,d3
  194.     exg        d2,d4
  195. *-------------------------------------------------------*
  196. .sort_y1y2:
  197. *-------------------------------------------------------*
  198.     cmp.w        d7,d2
  199.     bpl        .error
  200.     move.w        d4,d6
  201.     bmi        .error
  202.     sub.w        d2,d6
  203.     move.w        d3,d5
  204.     sub.w        d1,d5
  205.     bne.s        .no_vertical
  206.     tst.w        d2
  207.     bpl.s        .y1in
  208.     moveq        #0,d2
  209. .y1in:    cmp.w        d7,d4
  210.     bmi.s        .vertical_done
  211.     move.w        d7,d4
  212.     bra.s        .vertical_done
  213. *-------------------------------------------------------*
  214. .no_vertical:
  215. *-------------------------------------------------------*
  216.     tst.w        d2
  217.     bpl.s        .y1_inside
  218.     muls.w        d5,d2        ; dx*(y1-tc)
  219.     divs.w        d6,d2        ; dx*(y1-tc) / (y2-y1)
  220.     sub.w        d2,d1        ; x1' = x1 - (dx*(y1-tc)) / (y2-y1)
  221.     moveq        #0,d2        ; y1' = ty
  222. *-------------------------------------------------------*
  223. .y1_inside:
  224. *-------------------------------------------------------*
  225.     sub.w        d4,d7
  226.     bpl.s        .y2_inside
  227.     muls.w        d7,d5        ; dx*(bc-y2)
  228.     divs.w        d6,d5        ; dx*(bc-y2) / (y2-y1)
  229.     add.w        d5,d3        ; x2' = x2 + (dx*(bc-y2)) / (y2-y1)
  230.     add.w        d7,d4        ; y2' = by
  231. *-------------------------------------------------------*
  232. .y2_inside:
  233. *-------------------------------------------------------*
  234. .vertical_done:
  235. *-------------------------------------------------------*
  236.     move.w        width,d7
  237.     cmp.w        d1,d3
  238.     bpl.s        .sort_x1x2
  239.     exg        d1,d3
  240.     exg        d2,d4
  241. *-------------------------------------------------------*
  242. .sort_x1x2:
  243. *-------------------------------------------------------*
  244.     cmp.w        d7,d1
  245.     bpl        .error
  246.     move.w        d3,d5
  247.     bmi        .error
  248.     sub.w        d1,d5
  249.     move.w        d4,d6
  250.     sub.w        d2,d6
  251.     bne.s        .no_horizontal
  252.     tst.w        d1
  253.     bpl.s        .x1in
  254.     moveq        #0,d1
  255. .x1in:    cmp.w        d7,d3
  256.     bmi.s        .horizontal_done
  257.     move.w        d7,d3
  258.     bra.s        .horizontal_done
  259. *-------------------------------------------------------*
  260. .no_horizontal:
  261. *-------------------------------------------------------*
  262.     tst.w        d1
  263.     bpl.s        .x1_inside
  264.     muls.w        d6,d1        ; dy*(x1-lc)
  265.     divs.w        d5,d1        ; dy*(x1-lc) / (x2-x1)
  266.     sub.w        d1,d2        ; y1' = y1 - (dy*(x1-lc)) / (x2-x1)
  267.     moveq        #0,d1        ; x1' = lc
  268. *-------------------------------------------------------*
  269. .x1_inside:
  270. *-------------------------------------------------------*
  271.     sub.w        d3,d7
  272.     bpl.s        .x2_inside
  273.     muls.w        d7,d6        ; dy*(rc-x2)
  274.     divs.w        d5,d6        ; dy*(rc-x2) / (x2-x1)
  275.     add.w        d6,d4        ; y2' = y2 + (dx*(bc-y2)) / (y2-y1)
  276.     add.w        d7,d3        ; x2' = rc
  277. *-------------------------------------------------------*
  278. .x2_inside:
  279. *-------------------------------------------------------*
  280. .horizontal_done:
  281. *-------------------------------------------------------*
  282.  
  283.     endr
  284.     
  285.     move.l        screen,a0
  286.     move.w        scrwidth,d0            ; 2 * width screen
  287.     add.w        d0,d0
  288.     move.w        d4,d6                ; d6 = Y1-Y2 = dY
  289.     sub.w        d2,d6
  290.     beq        .h_line
  291.     move.w        d3,d5
  292.     sub.w        d1,d5                ; d5 = X2-X1 = dX
  293.     beq        .v_line    
  294.     bmi.s        .line1                ; dX < 0 ?
  295.     move.w        d2,d7
  296.     add.w        d1,d1                ; X2 > X1
  297.     move.w        d1,a1
  298.     bra.w        .n_line
  299. .line1:    neg.w        d5                ; X2 < X1
  300.     neg.w        d6
  301.     move.w        d4,d7
  302.     add.w        d3,d3
  303.     move.w        d3,a1     
  304. .n_line:
  305.     tst.w        d6
  306.     bpl.s        .n_line0
  307.     neg.w        d6
  308.     neg.w        d0
  309. .n_line0:
  310.     move.w        scrwidth,d1
  311.     add.w        d1,d1
  312.     cmp.w        d6,d5
  313.     bmi.s        .n_line2
  314. .n_line1:                    ; dX > dY
  315.     add.w        d6,d6
  316.     move.w        d6,d3
  317.     sub.w        d5,d6
  318.     move.w        d6,d4
  319.     sub.w        d5,d4
  320.  
  321.     mulu.w        d1,d7
  322.     add.l        a1,d7
  323.     lea        (a0,d7.l),a0            ; logscreen adress
  324.     move.w        a2,d2                ; pixel color
  325.  
  326. .lin1_lp2
  327.     tst.w        d6
  328.     bmi.s        .lin1_no_y
  329.     add.w        d4,d6
  330.     move.w        d2,(a0)+            ; display pixel
  331.     add.w        d0,a0
  332.     dbf        d5,.lin1_lp2
  333.     movem.l        (sp)+,d0-d7/a0-a2
  334.     rts
  335. .lin1_no_y    
  336.     add.w        d3,d6        
  337.     move.w        d2,(a0)+            ; display pixel
  338.     dbf        d5,.lin1_lp2
  339.     movem.l        (sp)+,d0-d7/a0-a2
  340.     rts
  341.     
  342. .n_line2:                    ; dX < dY
  343.     exg        d6,d5
  344.     add.w        d6,d6
  345.     move.w        d6,d3
  346.     sub.w        d5,d6
  347.     move.w        d6,d4
  348.     sub.w        d5,d4
  349.  
  350.     mulu.w        d1,d7
  351.     add.l        a1,d7
  352.     lea        (a0,d7.l),a0
  353.     move.w        a2,d2                ; pixel color
  354.  
  355. .lin2_lp:
  356.     tst.w        d6
  357.     bmi.s        .lin2_no_x
  358.      add.w        d4,d6
  359.     move.w        d2,(a0)+            ; display pixel
  360.     add.w        d0,a0 
  361.     dbf        d5,.lin2_lp
  362.     movem.l        (sp)+,d0-d7/a0-a2
  363.     rts
  364. .lin2_no_x:
  365.     add.w        d3,d6
  366.     move.w        d2,(a0)                ; display pixel
  367.     add.w        d0,a0 
  368.     dbf        d5,.lin2_lp
  369.  
  370. .error:    movem.l        (sp)+,d0-d7/a0-a2
  371.     rts
  372.     
  373. .h_line:                    ; Y1 = Y2
  374.     cmp.w        d1,d3
  375.     bge.s        .hline1    
  376.     exg        d1,d3
  377. .hline1:
  378.     sub.w        d1,d3
  379.     mulu.w        scrwidth,d2
  380.     lea        (a0,d2.l*2),a0            ; screen adress
  381.     add.w        d1,d1
  382.     add.w        d1,a0
  383. .for_h:    move.w        a2,(a0)+
  384. .shl:    dbf        d3,.for_h
  385.  
  386. .end_h:    movem.l        (sp)+,d0-d7/a0-a2
  387.     rts
  388.     
  389. .v_line:                    ; X1 = X2
  390.     tst.w        d6
  391.     bgt.s        .lvert2
  392.     exg        d2,d4    
  393.     neg.w        d6
  394. .lvert2:
  395.     moveq        #0,d5
  396.     move.w        scrwidth,d5
  397.     add.l        d5,d5
  398.     mulu.w        d5,d2
  399.     add.l        d2,a0
  400.     add.w        d1,d1
  401.     add.w        d1,a0
  402.     bra.s        .svl
  403. .for_v:    move.w        a2,(a0)
  404.     add.l        d5,a0
  405. .svl:    dbf        d6,.for_v
  406. .end_v:    movem.l        (sp)+,d0-d7/a0-a2
  407.     rts
  408.  
  409. *-------------------------------------------------------*
  410. *    Display player position on the map        *
  411. *-------------------------------------------------------*
  412. Display_Player_Position:
  413.     move.w    px,d3                ; Player's x position
  414.     ext.l    d3
  415.     sub.l    a2,d3
  416.     mulu.l    X_Y_map_Corr,d3
  417.     swap    d3
  418.     move.w    py,d6                ; Player's y position
  419.     ext.l    d6
  420.     sub.l    a3,d6
  421.     mulu.l    X_Y_map_Corr,d6
  422.     swap    d6
  423.     move.w    height,d4
  424.     subq.w    #1,d4
  425.     sub.w    d6,d4
  426.     move.l    sinpangle,d2            ; y player vector view
  427.     move.w    #14,d6
  428.     asr.l    d6,d2    
  429.     add.w    d4,d2
  430.     move.l    cospangle,d1            ; x player vector view
  431.     asr.l    d6,d1    
  432.     add.w    d3,d1
  433.     move.w    #$ffff,d5            ; display in white
  434.     bsr    display_line
  435.     rts
  436.  
  437. *-------------------------------------------------------*
  438.             bsslong
  439. *-------------------------------------------------------*
  440.  
  441. xmapmin:        ds.l    1
  442. ymapmin:        ds.l    1
  443. X_Y_map_Corr:        ds.l    1
  444.  
  445. map_enabled:        ds.b    1
  446.  
  447. *-------------------------------------------------------*
  448.             txtlong
  449. *-------------------------------------------------------*
  450.  
  451.         
  452.